package web.tag;

import domain.Announcement;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * announcement详细信息展示标签
 * 结合modal实现announcement的详细信息的展示
 *
 * @author shicm
 */
public class ShowAnnouncementInfoTag extends SimpleTagSupport {

    /** 要展示的公告 */
    private Announcement announcement;

    /**
     * 设置要展示的公告
     *
     * @param announcement 公告
     */
    public void setAnnouncement(Announcement announcement) {
        this.announcement = announcement;
    }

    /**
     * 展示公告详细信息
     *
     * @throws JspException JSP异常
     * @throws IOException IO异常
     */
    @Override
    public void doTag() throws JspException, IOException {
        JspWriter out = getJspContext().getOut();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String outPrint = "";
        outPrint += "<p><span class=\"fw-semibold\">公告ID: &nbsp;&nbsp;</span>"+announcement.getAnnouncementID()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">发布人: &nbsp;&nbsp;</span>"+announcement.getPublisher().getNickname()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">发布时间: &nbsp;&nbsp;</span>"+announcement.getPublishTime()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">公告内容: &nbsp;&nbsp;</span>"+announcement.getContent()+"</p>";
        out.write(outPrint);
    }
}
